<template>
  <div id="globalSider">
    <a-layout-sider
      v-if="loginUserStore.loginUser.id"
      class="sider"
      :width="200"
      :collapsed-width="80"
      :trigger="null"
      collapsible
      v-model:collapsed="collapsed"
      @mouseover="collapsed = false"
      @mouseleave="collapsed = true"
    >
      <a-menu
        mode="inline"
        v-model:selectedKeys="current"
        :items="menuItems"
        @click="doMenuClick"
      />
    </a-layout-sider>
  </div>
</template>
<script lang="ts" setup>
import { h, ref } from 'vue'
import { PictureOutlined, UserOutlined } from '@ant-design/icons-vue'
import { useRouter } from 'vue-router'
import { useLoginUserStore } from '@/stores/useUserLoginStore.ts'

const loginUserStore = useLoginUserStore()
const collapsed = ref(true)

// 菜单列表
const menuItems = [
  {
    key: '/',
    label: '公共图库',
    icon: () => h(PictureOutlined),
  },
  {
    key: `/mySpace`,
    label: '我的空间',
    icon: () => h(UserOutlined),
  },
]

const router = useRouter()
// 当前高亮菜单项
const current = ref<string[]>([])
// 监听路由变化，更新菜单高亮
router.afterEach((to, from, failure) => {
  current.value = [to.path]
})
// 路由跳转事件
const doMenuClick = ({ key }) => {
  router.push({
    path: key,
  })
}
</script>
<style scoped>
#globalSider .sider {
  transition: all 0.2s;
}

#globalHeader .title-bar {
  display: flex;
  align-items: center;
}

.logo {
  height: 45px;
}

.title {
  margin-left: 10px;
  color: black;
  font-size: 18px;
}
</style>
